 -------------------------------
--Custom4 SWEP - by Brian Nevec--
 -------------------------------
-----Part of SmodWeaponsPack-----
 -------------------------------
 
if SERVER then
	
	AddCSLuaFile("shared.lua");
	
end

if CLIENT then
	
	SWEP.PrintName			= "Custom 4";
	SWEP.Author				= "Brian Nevec";
	SWEP.Slot				= 2;
	SWEP.SlotPos			= 3;
	SWEP.Purpose			= "Fires lasers";
	SWEP.Instructions		= "Left Click: Fire";

	SWEP.Category			= "SMOD";
	
end

SWEP.Spawnable				= true;
SWEP.AdminSpawnable			= false;

SWEP.ViewModel				= "models/weapons/v_smg1.mdl";
SWEP.WorldModel				= "models/weapons/w_smg1.mdl";

SWEP.Weight					= 25;
SWEP.AutoSwitchTo			= false;
SWEP.AutoSwitchFrom			= false;

SWEP.Primary =
{
	
	ClipSize				= 45,
	DefaultClip				= 45,
	Automatic				= true,
	Ammo					= "smg1"
	
};

SWEP.Secondary =
{
	
	ClipSize				= -1,
	DefaultClip				= -1,
	Automatic				= false,
	Ammo					= "none"
	
};

SWEP.Sounds =
{

	Fire = Sound( "weapons/smg1/smg1_fire1.wav" )

};

function SWEP:Initialize()

	if SERVER then

		self:SetWeaponHoldType( "smg" );

	end

end

function SWEP:PrimaryAttack()
	
	if self.Weapon:CanPrimaryAttack( ) then
		
		if SERVER then
			
			local Pos = self.Owner:GetShootPos( );
			local Ang = self.Owner:GetAngles( );
			
			local spread = 0.8;
			
			Ang:RotateAroundAxis( Ang:Right( ), math.Rand( -spread, spread ) );
			Ang:RotateAroundAxis( Ang:Up( ), math.Rand( -spread, spread ) );
			
			local Beam = ents.Create( "smod_laserbeam" );
			
			if ValidEntity( Beam ) then
				
				Beam:SetPos( Pos );
				Beam:SetAngles( Ang );
				Beam:SetOwner( self.Owner );
				
				Beam:Spawn( );
				Beam:Activate( );
				
			end

		end
		
		self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK );
		self.Owner:SetAnimation( PLAYER_ATTACK1 );
		
		self.Owner:EmitSound( self.Sounds.Fire );
		
		self.Weapon:TakePrimaryAmmo( 1 );
		
	else
		
		self:Reload( );
		
	end
	
	self.Weapon:SetNextPrimaryFire( CurTime( ) + 0.07 );
	
	return false;
	
end

function SWEP:Reload()

	self.Weapon:DefaultReload( ACT_VM_RELOAD );
	
	return false;

end

function SWEP:SecondaryAttack()

	return false;

end

function SWEP:Deploy( )

	self.Weapon:SendWeaponAnim( ACT_VM_DRAW );

	return true;

end